package com.zyh.service.impl;

import com.zyh.dao.CategoryMapper;
import com.zyh.dao.TeaMapper;
import com.zyh.entity.Category;
import com.zyh.service.CategoryService;
import com.zyh.util.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class CategoryServiceImpl implements CategoryService {
    SqlSession sqlSession = null;
    @Override
    public void deleteOne(Integer categoryIdMy) {
        try {
            sqlSession = MybatisUtils.getSqlSession();
            CategoryMapper categoryMapper = sqlSession.getMapper(CategoryMapper.class);
            categoryMapper.deleteOne(categoryIdMy);
            sqlSession.commit();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            MybatisUtils.closeSqlSession(sqlSession);
        }
    }

    @Override
    public Category selectOneByName(String categoryName) {
        Category category = null;
        try {
            sqlSession = MybatisUtils.getSqlSession();
            CategoryMapper categoryMapper = sqlSession.getMapper(CategoryMapper.class);
            category = categoryMapper.selectOneByName(categoryName);
            sqlSession.commit();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            MybatisUtils.closeSqlSession(sqlSession);
        }
        return category;
    }

    @Override
    public List<Category> selectAll() {
        List<Category> categorieList = null;
        try {
            sqlSession = MybatisUtils.getSqlSession();
            CategoryMapper ategoryMapper = sqlSession.getMapper(CategoryMapper.class);
            categorieList = ategoryMapper.selectAll();
            sqlSession.commit();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            MybatisUtils.closeSqlSession(sqlSession);
        }
        return categorieList;
    }
}
